package mlz.d_javabean;

public class PersonDemo02 {
    public static void main(String[] args) {
        //方式一

        //创建IDCard对象
        IDCard idCard = new IDCard();
        idCard.idNum = "12222222222222";
        idCard.address = "浙江杭州";

        //创建person对象
        Person p1 = new Person();
        p1.setAge(18);
        p1.setName("张三");
        p1.setIdCard(idCard);
        System.out.println(p1.getAge());
        System.out.println(p1.getName());
        System.out.println(p1.getIdCard().address);

        System.out.println("--------------------------------");


        //方式二:
        Person p2 = new Person();
        p2.idCard = new IDCard(); //相当于没有对象 -> 空指针异常NullPointerException
        System.out.println(p2.idCard);//null
        //p2.null.idNum = "1333333333333";
        p2.idCard.idNum = "1333333333333";
        p2.idCard.address = "北京";
        p2.age = 20;
        p2.name = "李四";
        System.out.println(p2.getAge());
        System.out.println(p2.getName());
        System.out.println(p2.getIdCard().idNum);//内存地址值



        //创建IDCard的方式
        //IDCard idCard = new IDCard();
        //p2.idCard = new IDCard();


    }
}
